package com.yuw.control.userinfo;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yuw.bean.UserInfoBean;
import com.yuw.model.UserInfoModel;
import com.yuw.utils.EasyFactory;
import com.yuw.utils.MyUtils;

@WebServlet("/UserInfoQueryingControl")
public class UserInfoQueryingControl extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		UserInfoBean userInfoB = null;
		// 尝试取出是否查询的请求的表示字段的值
		String strFlag = request.getParameter("falg");
		if (strFlag != null && strFlag.equals("1")) {
			// 本次查询是从删除跳转过来的，需要从session缓存中取出之前缓存的查询条件实体
			userInfoB = (UserInfoBean) request.getSession().getAttribute("deleteQueryParamBean");
		} else {
			// 使用form表单的条件进行查询
			// 将表单转换为参数实体类
			userInfoB = MyUtils.convertRequest2BeanWithFileUpload(request, UserInfoBean.class);
		}
		// 调用Medol进行业务逻辑
		List<UserInfoBean> lst = EasyFactory.getNewInstance(UserInfoModel.class).queryUserInfoByParams(userInfoB);
		// 根据业务逻辑结果进行显示页面跳转处理
		// 将查询的结果集缓存到session对象中
		request.getSession().setAttribute("lstQueryUserInfos", lst);
		// 保留查询条件为 删除之后再次使用
		request.getSession().setAttribute("deleteQueryParamBean", userInfoB);

		// 转发到查询成功页面
		request.getRequestDispatcher("WEB-INF/pages/userInfo/UserInfoQuery.jsp").forward(request, response);

	}

}
